/**
 * 
 */
package org.istt.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * @author Huy
 *
 */
@Entity
@Table(name="TBL_ATTACH_FILE_DETAIL"
    ,schema="dbo"
    ,catalog="onegate"
)
public class AttachFileDetail extends BaseObject<Long> implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6943950924594951554L;
	
	private Long id;
	private File file;
	private AttachFile attachFile;
	private Long numberOfcopy;
	private DocumentType documentType;
	
	@Id
	@Column(name = "ID", unique = true, nullable = false)
	@GeneratedValue(strategy=IDENTITY)
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
	@JoinColumn(name="FILE_ID")
	public File getFile() {
		return file;
	}
	
	public void setFile(File file) {
		this.file = file;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ATTACH_FILE_ID")
	public AttachFile getAttachFile() {
		return attachFile;
	}

	public void setAttachFile(AttachFile attachFile) {
		this.attachFile = attachFile;
	}
	
	@Column(name="NUMBER_OF_COPY")
	public Long getNumberOfcopy() {
		return numberOfcopy;
	}

	public void setNumberOfcopy(Long numberOfcopy) {
		this.numberOfcopy = numberOfcopy;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="DOCUMENT_TYPE_ID")
	public DocumentType getDocumentType() {
		return documentType;
	}

	public void setDocumentType(DocumentType documentType) {
		this.documentType = documentType;
	}

	@Override
	public String toString() {
		
		return null;
	}

	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof AttachFileDetail)) return false;

		final AttachFileDetail ao = (AttachFileDetail) o;

        if (!getFile().getId().equals(ao.getFile().getId())) return false;
        if (!getAttachFile().getId().equals(ao.getAttachFile().getId())) return false;
        if (!getDocumentType().getId().equals(ao.getDocumentType().getId())) return false;

		return true;
	}

	public int hashCode() {
		int result;
		result = getFile().getId().hashCode() + getAttachFile().getId().hashCode() + getDocumentType().getId().hashCode() + numberOfcopy.hashCode();
		result = 29 * result;
		return result;
	}
	
}
